package com.hp.mvc;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("stu")
public class StudentController {

    //以xx-xxx-xxx获得Student参数
    @PostMapping("save")
    public String save(Student student){
        System.out.println(student);
        return "success";
    }

    //以JSON获得Student参数 @RequestBody的作用是将JSON转换为Java对象
    //将数据直接返回给前端，如果是Java对象会自动转换为JSON格式
    @ResponseBody
    @PostMapping("save2")
    public String save2(@RequestBody Student student){
        System.out.println(student);
//        User user = new User();
//        user.setUsername("test");
//        user.setPassword("123");
//        List<User> users = Arrays.asList(new User("test-1", "123"),
//                new User("test-2", "123"));
//        return users;
        return "哈哈哈哈";
    }
}
